# This code is hosted on http://code.google.com/p/lenthorp/
# Freely available for use in applications, but should NOT be modified
# Email all comments to lenthorpresearch@gmail.com

from PricingEngine_DisplacedDiffusionAnalyticalMod import *
from CalibratorMod import *

def runTest():
    mp = ModelParameters()
    mp.p['type'] = 'call'
    dde = DisplaceDiffusionAnalytical(mp)

    op = OptimiseParameters()
    op.p['vol'] = 0.35
    op.p['delta'] = 0.1
    op.setBound('vol', 0, True)
    op.setBound('vol', 2, False)
    op.setBound('delta', -0.9999, True)
    op.setBound('delta', 0.9999, False)

    ##pp = PricingParameters(['strike', 'tenor', 'rate', 'initial'])
    ##pp.addPricingSet([100, 30, 0.05, 100, 0],0)
    ##dde.setUpParameters(pp,op)
    #print(dde.getPrice())


    pp = PricingParameters(['strike', 'tenor', 'rate', 'initial'])
    pp.addPricingSet([100, 1, 0.05, 100], 3.9)
    pp.addPricingSet([30, 10, 0.05, 100], 26.47)
    pp.addPricingSet([160, 15, 0.05, 100], 1.99)
    pp.addPricingSet([110, 3, 0.05, 100], 1.72)
    dde.setUpParameters(pp,op)
    dm = SumOfSquaresDistance()
    ##print(dde.getPrice())
    #c = ScipyFminBFGSCalibrator(dde, pp, op, dm)
    c = ScipyFminSLSQPCalibrator(dde, pp, op, dm)
    #print(c.calibrate())
    res = dde.getPrice()
    return res

if __name__ == "__main__":
    res = runTest()
    print(res)